<?php

session_start();
ob_start();
include_once 'inc/fire/FirePHP.class.php';

function __autoload($class_name) {
    $fullclasspath = "";
    $suffix = "";
    if (!file_exists('../alania21/inc/' . $fullclasspath . $class_name . ".php")) {
        if (!file_exists('../alania21/inc/' . $fullclasspath . $class_name . ".class.php")) {
            if (file_exists('../alania21/inc/utility/' . $class_name . ".class.php")) {
                $fullclasspath = "utility/";
                $suffix = ".class";
            }
        } else {
            $suffix = ".class";
        }
    }
    //echo '../alania21/inc/' . $fullclasspath . $class_name . $suffix . '.php<br />';
    require_once '../alania21/inc/' . $fullclasspath . $class_name . $suffix . '.php';
}

//$firephp = FirePHP::getInstance(true);
//
$accion = 1;
$page = new Template($accion);
$page->setText();
//echo "<pre>";
////$firephp->log($page->getText(), 'gettext');
//"hijos":[{"#text":{"hijos":[],"0":"Documento sin t\u00edtulo","attributes":""}}]
//$firephp->log($page->getText(),'gettext');
preg_match_all('/(\[\[@)(?<name>(?:[a-z][a-z0-9_]*))(\]\])/is', $page->getText(), $matches);
$page->set($matches['name'][0], '{"#text":{"hijos":[],"0":"[@' . $matches['name'][0] . ']","attributes":""}}');
$page->setText();
$pag= $page->outputHTML();
//echo $pag;
$ht=new XmlDomConstruct();

$datos = $ht->html2json($pag);
//$firephp->log($datos,'datos');
//echo $ht->json2html($datos);
//$pag2=json2html($datos);
echo preg_match_all('/(\[\{"#text":\{"attributes":"","hijos":\[\],"0":"\[@)(?<name>(?:[a-z][a-z0-9_]*))(\]"\}\}\])/is', $datos, $matches);
echo "<pre>";
print_r($matches);
print_r( preg_replace('/(\[\{"#text":\{"attributes":"","hijos":\[\],"0":"\[@log\]"\}\}\])/is', '[[@'.$matches['name'][0].']]', $datos));
//echo $datos;
echo "</pre>";

?>
